var str_general_error = "Due to some technical reasons we are unable to connect you at the moment. Please try again after some time. If you continue facing this problem, please send us an email at support@tradekey.com.";
var isMiniOpen=0;

var trademate = {
                 B2C : 1,
                 C2C : 2
                };

var trademate_status = {
                        ONLINE : "ONLINE",
                        OFFLINE : "OFFLINE",
                        BUSY : "BUSY",
                        AWAY : "AWAY"
                      };
					  
var new_trademate_status = {
                        AVAILABLE : "ONLINE",
                        OFFLINE : "OFFLINE",
                        BUSY : "BUSY",
                        AWAY : "AWAY"
                      };


var trademate_c2c_images = {
                            ONLINE:"chat_status_online.png",
                            ONLINE_OLDER:"chat_status_online.gif",
                            OFFLINE:"chat_status_offline.png",
                            OFFLINE_OLDER:"chat_status_offline.gif",
                            BUSY:"chat_status_busy.png",
                            BUSY_OLDER:"chat_status_busy.gif",
                            AWAY:"chat_status_away.png",
                            AWAY_OLDER:"chat_status_away.gif"
                          };
						  
var new_trademate_c2c_images = {
                            AVAILABLE:"chat_status_online.png",
                            AVAILABLE_OLDER:"chat_status_online.gif",
                            OFFLINE:"chat_status_offline.png",
                            OFFLINE_OLDER:"chat_status_offline.gif",
                            BUSY:"chat_status_busy.png",
                            BUSY_OLDER:"chat_status_busy.gif",
                            AWAY:"chat_status_away.png",
                            AWAY_OLDER:"chat_status_away.gif"
                          };
						  
var trademate_c2c_images_height=33;
var trademate_c2c_images_width=98;

function loadjscssfile(filename, filetype, callback)
{
	if(filetype=="js")
	{
		var html_doc = document.getElementsByTagName('head').item(0);
		var js=document.createElement('script');
		js.setAttribute("type","text/javascript");
		js.setAttribute("src", filename);
		js.defer = true;

		if(document.all)
		{
			if(js.readyState)
			{
				if(callback != null)
				{
					js.onreadystatechange = function(){if(js.readyState == "loaded" || js.readyState == "complete"){eval(callback);}};
				}
				html_doc.appendChild(js);
			}
			else
			{
				html_doc.appendChild(js);
				if(callback != null) eval(callback);
			}
		}
		else
		{
			if(callback != null)
				js.onload = function(){eval(callback);};
			html_doc.appendChild(js);
		}
	}
	else if(filetype=="css")
	{
		var fileref=document.createElement("link");
		fileref.setAttribute("rel", "stylesheet");
		fileref.setAttribute("type", "text/css");
		fileref.setAttribute("href", filename)
	}
	if(typeof fileref!="undefined")
		document.getElementsByTagName("head")[0].appendChild(fileref)
}

if(typeof(JSON) == "undefined")
{
	loadjscssfile(chat_js_url + "cjs/json2.js", "js", "");
}

if(typeof(jQuery) != "function")
	loadjscssfile(chat_js_url + "jquery/jquery-1.3.2.min.js", "js", "onafter_jquery()");
else
	onafter_jquery();


function onafter_jquery()
{
    if (typeof(is_buyer) != "undefined" && is_buyer)
    {
        if (typeof(chat_im_presence_url) != "undefined")
        {
            jQuery(window).ready(function()
            {
                if(typeof(chat_image_url)!="undefined")
                {
                    jQuery("body").append("<img id='trademate_img_size' src='"+chat_image_url+get_image_name(trademate.C2C,trademate_status.OFFLINE)+"' style='position:fixed;visibility:hidden;' />");
                    jQuery("#trademate_img_size").load(function()
                                                        {
                                                            set_image_size();
                                                        }
                                                        );
                }
				//@b2c_adnan
                c2c_get_status();
                c2c_get_status_new();
            });
        }
        else if(typeof(enc_c2c_buyer_login) != "undefined")
        {
            window.onbeforeunload = function (e)
            {
                var message = "";

                e = e || window.event;

                if (e)
                    e.returnValue = message;

                return message;
            }

            setTimeout("init_c2c_buyer_session()", 10);
        }
    }
   /* else
    {
        window.onbeforeunload = function (e)
        {
            var message = "";

            e = e || window.event;

            if (e)
                e.returnValue = message;

            return message;
        }

        setTimeout("init_c2c_seller_session()", 10);
    }*/

    (function($){$.fn.rc4=function(settings){
            var defaults={key:null,method:"encrypt",callback:null};
            var options=$.extend(defaults,settings);
            if($.fn.rc4.ctrlrInst==null){$.fn.rc4.ctrlrInst=new $.fn.rc4.ctrlr(options);}
            return this.each(function(){$.fn.rc4.ctrlrInst.settings=options;
                $.fn.rc4.ctrlrInst.container=this;$.fn.rc4.ctrlrInst.initialise(this);
    });}
    $.extend({hexEncode:function(data){
        var b16D='0123456789abcdef';var b16M=new Array();
        for(var i=0;i<256;i++){b16M[i]=b16D.charAt(i>>4)+b16D.charAt(i&15);}
        var result=new Array();for(var i=0;i<data.length;i++){result[i]=b16M[data.charCodeAt(i)];}
        return result.join('');
    },hexDecode:function(data){var b16D='0123456789abcdef';var b16M=new Array();
        for(var i=0;i<256;i++){b16M[b16D.charAt(i>>4)+b16D.charAt(i&15)]=String.fromCharCode(i);}
        if(!data.match(/^[a-f0-9]*$/i))return false;if(data.length%2)data='0'+data;
        var result=new Array();var j=0;for(var i=0;i<data.length;i+=2){result[j++]=b16M[data.substr(i,2)];}
        return result.join('');
    },rc4Encrypt:function(key,pt){
        s=new Array();for (var i=0;i<256;i++){s[i]=i;};var j=0;var x;
        for (i=0;i<256;i++){j=(j+s[i]+key.charCodeAt(i % key.length)) % 256;x=s[i];s[i]=s[j];s[j]=x;}
        i=0;j=0;var ct='';for (var y=0;y<pt.length;y++){i=(i+1) % 256;j=(j+s[i]) % 256;x=s[i];s[i]=s[j];s[j]=x;
        ct+=String.fromCharCode(pt.charCodeAt(y) ^ s[(s[i]+s[j]) % 256]);}return ct;
    },rc4Decrypt:function(key,ct){return $.rc4Encrypt(key,ct);
    },rc4EncryptStr:function(str,key){return $.hexEncode($.rc4Encrypt(key,unescape(encodeURIComponent(str))));
    },rc4DecryptStr:function(hexStr,key){return decodeURIComponent(escape($.rc4Decrypt(key,$.hexDecode(hexStr))));}
    });
    $.rc4={};$.fn.rc4.ctrlrInst=null;$.fn.rc4.ctrlr=function(settings){this.settings=settings;};var ctrlr=$.fn.rc4.ctrlr;
    ctrlr.prototype.initialise=function(){
        if(this.settings.key){if(this.settings.method){if($.trim(this.settings.method.toUpperCase())=="ENCRYPT"){
            this.setObjectValue($.hexEncode($.rc4Encrypt(this.settings.key,this.getObjectValue())))}
        if($.trim(this.settings.method.toUpperCase())=="DECRYPT"){
            this.setObjectValue($.rc4Decrypt(this.settings.key,$.hexDecode(this.getObjectValue())));}}};
    }
    ctrlr.prototype.getObjectValue=function(){
        if($.fn.rc4.ctrlrInst.container.innerHTML){return $.fn.rc4.ctrlrInst.container.innerHTML;}
        if($.fn.rc4.ctrlrInst.container.value){return $.fn.rc4.ctrlrInst.container.value;}}
    ctrlr.prototype.setObjectValue=function(data){
        if($.fn.rc4.ctrlrInst.container.innerHTML){$.fn.rc4.ctrlrInst.container.innerHTML=data;}
        if($.fn.rc4.ctrlrInst.container.value){$.fn.rc4.ctrlrInst.container.value=data;}}
    })(jQuery);

}

function set_image_size()
{
    if(trademate_c2c_images_height > jQuery("#trademate_img_size").height())
    {
        setTimeout("set_image_size()", 100);
        return;        
    }
    
    trademate_c2c_images_height=jQuery("#trademate_img_size").height();
    trademate_c2c_images_width=jQuery("#trademate_img_size").width();
    jQuery(".status_span").height(trademate_c2c_images_height).width(trademate_c2c_images_width);
}
//for Ejabber System
function c2c_get_status_new()
{
	if(typeof(arr_ejabberuser_objects) == "undefined")
        return

	userid_array = new Array();
	var child_parent_map = new Array();
	
	for (var index in arr_ejabberuser_objects)
    {
		obj_user_info = arr_ejabberuser_objects[index];
	    if(typeof obj_user_info.child_id != 'undefined'){
			userid_array[userid_array.length] = "0"+obj_user_info.child_id;
			child_parent_map["0"+obj_user_info.child_id] = obj_user_info.user_id;
		}
		userid_array[userid_array.length] = obj_user_info.user_id;
		var str_span = "";
        jQuery("span[id='"+ obj_user_info.span_id + "']").map(function()
        {
            if(obj_user_info.offline_link != ""){
			str_span = "<span class='status_span' online = '0' id_online = '0' onclick=\"" + obj_user_info.offline_link + "\" style='cursor:pointer;height:"+trademate_c2c_images_height+"px;width:"+trademate_c2c_images_width+"px;display:inline-block;margin-right:2px;background-repeat:no-repeat;background-image:url("+ chat_image_url + get_image_name(trademate.C2C, trademate_status.OFFLINE) + ");' title='Offline' alt='Offline'>&nbsp;</span>";
			}else{
			str_span = "<span class='status_span' online = '0' id_online = '0' onclick=\"" + obj_user_info.offline_link + "\" style='height:"+trademate_c2c_images_height+"px;width:"+trademate_c2c_images_width+"px;display:inline-block;margin-right:2px;background-repeat:no-repeat;background-image:url("+ chat_image_url + get_image_name(trademate.C2C, trademate_status.OFFLINE) + ");' title='Offline' alt='Offline'>&nbsp;</span>";
            }
			jQuery(this).html(str_span);
        });
	}
	var place_holder = "CHAT_STATUS_";
    userid_array = array_unique(userid_array);
		if(userid_array.length > 0)
		{
				userid_array = userid_array.toString();
				var userids = userid_array.replace(/,/g,"_");
				proxy_url += userids;
			    var result1 = null;
				jQuery.get(proxy_url, {name:null},function(data){parent_child_status(data);});
				var tm = 1;
				
				function parent_child_status(data)
				{
					myObject = {data : []};
					if(data)
					{
						myObject = eval('(' + data + ')');					
					}
					var status_img = "";
				
					if(myObject.data.length > 0)
					{
						for(var f=0; f < myObject.data.length;f++)
						{	
						    user_id = myObject.data[f].ID;
					
							  if((f-1 > -1) &&
							    (typeof arr_ejabberuser_objects[myObject.data[f].ID] != 'undefined' ) &&
								(typeof arr_ejabberuser_objects[myObject.data[f].ID].child_id != 'undefined') &&
								(myObject.data[f-1].ID == "0"+arr_ejabberuser_objects[myObject.data[f].ID].child_id))
								{
									//alert("parent-skiped");
									// sip this parent cause child online	
								}   // ejabber
							else
							{ 
									user_status = myObject.data[f].STATUS;
									user_status = user_status.toLocaleString().toUpperCase();

									if(user_status == "AVAILABLE")
										user_status  = trademate_status.ONLINE;

									title_img = user_status.toLocaleString();

									if(typeof arr_ejabberuser_objects[myObject.data[f].ID] != 'undefined' ){
									//alert("show parent "+user_id);
										jQuery("span[id='"+ place_holder + user_id +"']").map(function(){
										str_title = jQuery(this).attr("title");
										jQuery(this).html("<span class='status_span' online = '1' id_online = '"+user_id+"' style='cursor:pointer;height:"+trademate_c2c_images_height+"px;width:"+trademate_c2c_images_width+"px;display:inline-block;margin-right:2px;background-repeat:no-repeat;background-image:url("+ chat_image_url + get_image_name(trademate.C2C, user_status) + ");' onclick=\"OpenCustomLink('" + user_id + "');\" title='" + title_img + "' alt='"+ title_img +"'>&nbsp;</span>");
										});
									}
									else{
									//alert("show child "+user_id);
										jQuery("span[id='"+ place_holder + child_parent_map[user_id] +"']").map(function(){
										str_title = jQuery(this).attr("title");
										
										jQuery(this).html("<span class='status_span' online = '1' id_online = '" + user_id + "' style='cursor:pointer;height:"+trademate_c2c_images_height+"px;width:"+trademate_c2c_images_width+"px;display:inline-block;margin-right:2px;background-repeat:no-repeat;background-image:url("+ chat_image_url + get_image_name(trademate.C2C, user_status) + ");' onclick=\"OpenCustomLink('"+ user_id+ "');\" title='" + title_img + "' alt='"+ title_img +"'>&nbsp;</span>");
										});
									}
							}
						}
					}
				}
				
		}
	}
	
function c2c_get_status()
{
	if(typeof(arr_user_objects) == "undefined")
        return

    userid_array = new Array();

    for (var index in arr_user_objects)
    {
        obj_user_info = arr_user_objects[index];
        userid_array[userid_array.length] = obj_user_info.user_id;

        var str_span = "";

        jQuery("span[id='"+ obj_user_info.span_id + "']").map(function()
        {
            str_span = "<span class='status_span' onclick=\"" + obj_user_info.offline_link + "\" style='cursor:pointer;height:"+trademate_c2c_images_height+"px;width:"+trademate_c2c_images_width+"px;display:inline-block;margin-right:2px;background-repeat:no-repeat;background-image:url("+ chat_image_url + get_image_name(trademate.C2C, trademate_status.OFFLINE) + ");' title='Offline' alt='Offline'>&nbsp;</span>";
            jQuery(this).html(str_span);
        });
    }
    var place_holder = "CHAT_STATUS_";
    userid_array = array_unique(userid_array);
    if(userid_array.length > 0)
    {
		//@b2c_adnan
		jQuery.getJSON(chat_im_gw_resolution_url +"?callback=?",
        {
            "action": "imGatewayResolution",
            "userids": userid_array.toString(),
            "type": 2,
            "rtype": "JSON",
            "noCache": Math.floor(Math.random()*100001)},
            function(img_data)
            {
                img_users = new Array();
                img_server = new Array();
                if(img_data.response.success)
                {
                    if(img_data.response.IMG != null && img_data.response.IMG.IMG != null)
                    {
                        for(var img_index=0; img_index < img_data.response.IMG.IMG.length-1; img_index++)
                        {
                            var img_temp = img_data.response.IMG.IMG[img_index].split("|");
                            user_id = img_temp[0];
                            enc_email_id = img_temp[1];
                            bot_type = "";
                            gw_server = img_temp[2];
                            status_img  = img_temp[3];
                            title_img = status_img.toLocaleString().capitalize();

                            jQuery("span[id='"+ place_holder + user_id +"']").map(function(){
                            str_title = jQuery(this).attr("title");
                            jQuery(this).html("<span id='CHAT_STATUS_" + enc_email_id + "' class='status_span' style='cursor:pointer;height:"+trademate_c2c_images_height+"px;width:"+trademate_c2c_images_width+"px;display:inline-block;margin-right:2px;background-repeat:no-repeat;background-image:url("+ chat_image_url + get_image_name(trademate.C2C, status_img) + ");' onclick='chat_start_chat(\"" + user_id +"\",\""+ enc_email_id +"\",\""+ str_title +"\",\""+ bot_type +"\", "+ gw_server + ");' title='" + title_img + "' alt='"+ title_img +"'>&nbsp;</span>");
                            });

                            if(typeof(img_users[parseInt(img_temp[2])]) == "undefined")
                                img_users[parseInt(img_temp[2])] = new Array(img_temp[0]);
                            else
                                img_users[parseInt(img_temp[2])][img_users[parseInt(img_temp[2])].length] = img_temp[0];
                        }
                    }
                }
            }
        );
	}
}

function chat_start_chat(chat_user_id, chat_im_id, str_title, bot_type, server)
{
    var arr_title = str_title.split("-{marker}--");
    
    var product_id = arr_title[0];
    var product = arr_title[1];
    var offer_type = arr_title[2];
    
    var win = window.open(chat_site_url + "index.html?action=im_c2cchat_c2cbuyerwindow&seller_id="+chat_user_id+"&seller_im_id="+chat_im_id+"&server="+server+"&bot="+bot_type+"&product_id="+product_id+"&product="+product+"&offer_type="+offer_type , "CHAT_WINDOWS_"+ chat_user_id, "location=no,toolbar=0,resizable=1,status=no,width=751,height=470");

    win.focus();
}


function init_c2c_buyer_session()
{
	try
    {
        jQuery.getJSON
        (
            chat_im_server_url +"?callback=?",
            {
                "action": "C2CSessionInitiation",
                "med": medium,
				"SellerIMId": enc_seller_im_id,
				"Resource": enc_resource,
                "SellerFullName": enc_seller_full_name,
                "BuyerFullName": enc_buyer_full_name,
                "ssid": enc_server,
                "company": enc_company,
                "country": enc_country,
                "salutation": enc_salutation,
                "productId": enc_product_id,
                "product": enc_product,
                "offerType": enc_offer_type,
                "anonymousUser": enc_is_guest_login,
				"rtype": "JSON"
            },
            function(data)
            {
                if(data.response.success)
                {
                    var enc_chat_identifier = data.response.result;
                    var url = c2cchat_url + "&contactId=" + enc_c2c_buyer_login + "&resource=" + enc_resource + "&anonymousUser=" + enc_is_guest_login + "&buyerSeller=" + enc_is_buyer + "&buyerName=" + enc_buyer_full_name +"&sellerName=" + enc_seller_full_name + "&chatIdentifier=" + enc_chat_identifier + "&company=" + enc_company + "&country=" + enc_country + "&salutation=" + enc_salutation + "&product=" + enc_product + "&productId=" + enc_product_id + "&offerType=" + enc_offer_type +  "&type=1";
                    jQuery("#chatwindow").html("<iframe src='"+ url +"' width='100%' height='100%' > </iframe>");

                }
                else
                {
                    var error = data.response.error;

                    if (error != null && typeof(error) != "undefined" && error != "")
                        jQuery("#chatwindow").html("<div style='position:absolute; top: 100px; left:50px; width:500px; color:red; font: 12px tahoma, arial, verdana;'>" + error + "</div>");
                    else
                        jQuery("#chatwindow").html("<div style='position:absolute; top: 100px; left:50px; width:500px; color:red; font: 12px tahoma, arial, verdana;'>" + str_general_error + "</div>");
                }
            }
        );
	}
    catch (e)
    {
        jQuery("#chatwindow").html("<div style='position:absolute; top: 100px; left:50px; width:500px; color:red; font: 12px tahoma, arial, verdana;'>"+ str_general_error +"</div>");
	}

}


function init_c2c_seller_session()
{
	try
    {
        jQuery.getJSON
        (
            chat_im_server_url +"?callback=?",
            {
                "action": "C2CSessionInitiation",
				"sid": sid,
                "sellerId": enc_seller_id,
				"rtype": "JSON"
            },
            function(data)
            {
                if(data.response.success)
                {
                    var url = data.response.result;
                    jQuery("#chatwindow").html("<iframe src='"+ url +"' width='100%' height='100%'> </iframe>");
                }
                else
                {
                    var error = data.response.error;

                    if (error != null && typeof(error) != "undefined" && error != "")
                        jQuery("#chatwindow").html("<div style='position:absolute; top: 100px; left:50px; width:500px; color:red; font: 12px tahoma, arial, verdana;'>" + error + "</div>");
                    else
                        jQuery("#chatwindow").html("<div style='position:absolute; top: 100px; left:50px; width:500px; color:red; font: 12px tahoma, arial, verdana;'>" + str_general_error + "</div>");

                }
            }
        );
	}
    catch (e)
    {
        jQuery("#chatwindow").html("<div style='position:absolute; top: 100px; left:50px; width:500px; color:red; font: 12px tahoma, arial, verdana;'>" + str_general_error + "</div>");
	}
}


function array_unique(input_arr)
{
    var tmp_arr = new Array();
    var input_len = input_arr.length;
    for(input_count=0;input_count<input_len;input_count++)
    {
    	var tmp_len = tmp_arr.length;
	    for(tmp_count=0;tmp_count<tmp_len;tmp_count++)
	    {
	    	if(input_arr[input_count].toString() == tmp_arr[tmp_count].toString())
	    		break;
		}
		if(tmp_count == tmp_len)
			tmp_arr[tmp_len] = input_arr[input_count];
 	}
    return tmp_arr;
}


function get_image_name(trademate_type, image_status,system)
{
	var ie_version = get_ie_version();
    var image_name = "";
	if(isNaN(system))
		system = 0;//for Old Chat Server
	
    switch(trademate_type)
    {
        case trademate.B2C:
            break;

        case trademate.C2C:
            if (ie_version >= 1 && ie_version <= 6)
            {
                if (image_status == trademate_status.ONLINE)
                    image_name = trademate_c2c_images.ONLINE_OLDER;

                else if (image_status == trademate_status.OFFLINE)
                    image_name = trademate_c2c_images.OFFLINE_OLDER;

                else if (image_status == trademate_status.BUSY)
                    image_name = trademate_c2c_images.BUSY_OLDER;

                else if (image_status == trademate_status.AWAY)
                    image_name = trademate_c2c_images.AWAY_OLDER;
            }
            else
            {
			
                if (image_status == trademate_status.ONLINE)
                    image_name = trademate_c2c_images.ONLINE;
				
               else  if (image_status == trademate_status.OFFLINE)
                    image_name = trademate_c2c_images.OFFLINE;

                else if (image_status == trademate_status.BUSY)
                    image_name = trademate_c2c_images.BUSY;

                else if (image_status == trademate_status.AWAY)
                    image_name = trademate_c2c_images.AWAY;
            }

            break;
    }
    return image_name;
}


function get_ie_version()
{
  var rv = -1;

  if (navigator.appName == 'Microsoft Internet Explorer')
  {
        var ua = navigator.userAgent;
        var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");

        if (re.exec(ua) != null)
            rv = parseFloat( RegExp.$1 );
  }

  return rv;
}
//@mohsinkhalid
function InsertIntoStore(ukey)
	{
	var expiry = 1;
		if(get_cookie('userlist') == ""){
					/*var users = new Object();
					users[0] = {userid:ukey};
					var user = JSON.stringify(users);
					var expiry = 1;
					alert(users.toSource());alert(expiry);	
					if (typeof(cookie_domain) != "undefined")
					set_cookie("userlist",user,expiry,"/",cookie_domain);
					else
					set_cookie("userlist",user,expiry,"/");*/
					window.open(chat_site_url+'index.html?action=im_c2cchat_trademateweb&id='+ukey,'Trademate','resizable=no,width=700,height=750');
					isMiniOpen=1;
					/*return true;*/
		}
		else{
		try{
						var users = get_cookie('userlist');
						var user = JSON.parse(users);
						
							Object.size = function(obj) {
								var size = 0, key;
								for (key in obj) {
									if (obj.hasOwnProperty(key)) size++;
								}
								return size;
								};
								
							var size = Object.size(user);
						
							if (size > 0)
							{
								var n =0;
								var m = 0;
								for(m; m<size; m++)
								{
								if(user[m].userid == ukey)
								return false;
								}
								
								for(n; n<=size; n++){
						
										 if(user[n].userid != "" && user[n].userid != ukey && n == size-1 ) {
												 n = n+1;
												 user[n] = {userid:ukey};
						
												 var users = JSON.stringify(user);
													if (typeof(cookie_domain) != "undefined")
													set_cookie("userlist",users,expiry,"/",cookie_domain);
													else
													set_cookie("userlist",users,expiry,"/");
													 
												 }
									 }
							}
						
					}
					catch(error)
					{
						
						var users = new Object();
						users[0] = {userid:ukey};
						var user = JSON.stringify(users);
						return true;
					}
		
		}
		
	}
//@mohsinkhalid
function OpenCustomLink(id)
{ 
	if(document.getElementById('pingmember')==null)
	{
			if(navigator.product == 'Gecko'){
		   var trademateplug = navigator.plugins["Trademate"];
		   if( trademateplug != null ) {
				 try
				{
					window.location = 'trademate:'+id;
					isMiniOpen=1;
				}
				catch(error)
				{
					 InsertIntoStore(id);
				}
			}
		   else {

			InsertIntoStore(id);

		   }
	   }
	   else{
		if (navigator.appName == "Microsoft Internet Explorer" && document.getElementById("tproto").protocolLong=="Unknown Protocol")
			{
				 InsertIntoStore(id);
			}
			else
			{
				  try
					{
						window.location = 'trademate:'+id;
						isMiniOpen=1;
					}
					catch(error)
					{
						 InsertIntoStore(id);
					}

			   }

	   }


	}
	else
	{
	document.getElementById('pingmember').focus();
	}
}

String.prototype.capitalize = function() {
    return this.charAt(0).toUpperCase() + this.slice(1);
}

function connectWithSeller(uid,mem_userid,offer_value,mini_guid,bypass_status,page,country,site)
{

	var bypass_status = bypass_status || 0;
	
	if(uid!=mem_userid && isMiniOpen==0)
	{
		var status;
		var uid_online ;
	//	if (bypass_status)
	//		status = 1;
	//	else
{
			status = document.getElementById('CHAT_STATUS_'+uid).childNodes[0].getAttribute('online');
			uid = document.getElementById('CHAT_STATUS_'+uid).childNodes[0].getAttribute('id_online');
		}

		if(status==1)
		{
			jQuery.ajax({
						url:"/index.html?action=im_c2cchat_tradematemini&partner="+uid+"&offer_value=" + offer_value+"&mini_guid=" + mini_guid + "&isTradekeyPage=1"+ "&page_url=" + page + "&site_source=" + site + "&userip=" + country,
						dataType:"html",
						success:function(data, textStatus, jqXHR){
						jQuery("#trademate_Mini").html(data);
						}
					 });
			isMiniOpen=1;
		}
		else if(status==0)
		{
			return false;
		}
		else
		{
			return false;
		}
			
	}
}